<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <a href="http://www.sohu.com">点击跳转</a>
    <script>
      var aEle = document.querySelector("a");
      aEle.onclick = function (e) {
        var e = e || window.e;
        e.preventDefault();
        var res = confirm("你确定吗？");
        if (res) {
          window.location.href = "http://www.baidu.com";
        }
        // return false;要放在最后
      };
    </script>
  </body>
</html>
